package com.example.system.controller;


import com.example.core.constants.HttpConstants;
import com.example.core.controller.BaseController;
import com.example.core.result.Res;
import com.example.redis.service.RedisService;
import com.example.system.entity.DTO.AddUserDTO;
import com.example.system.entity.DTO.LoginDTO;
import com.example.system.entity.VO.SysUserInfoVO;
import com.example.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/sysUser")
public class SysUserController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private RedisService redisService;

    @PostMapping("/login")
    public Res<String> login(@RequestBody LoginDTO loginDTO) {
        return sysUserService.login(loginDTO);
    }

    @PostMapping("/add")
    public Res<Void> add(@RequestBody AddUserDTO addUserDTO) {
        return super.toR(sysUserService.add(addUserDTO));
    }


    @GetMapping("/info")
    public Res<SysUserInfoVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return sysUserService.getUserInfo(token);
    }

    @DeleteMapping("/logout")
    public Res<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token) {
        return super.toR(sysUserService.logout(token));
    }

}
